//
//  PCTabBarVC.m
//  PhotoCircle
//
//  Created by wujungao on 12/10/15.
//  Copyright © 2015 wujungao. All rights reserved.
//

#import "PCTabBarVC.h"
#import "plusBackgroundView.h"
#import "PCUserLoginViewController.h"
#import "bottomView.h"

@interface PCTabBarVC ()

@property(nonatomic,strong)plusBackgroundView *plusBackgroundView;

@property(nonatomic,assign)BOOL isShowingplusBackgroundView;

@end

@implementation PCTabBarVC

#pragma mark - PCTabBarVC method
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self configTabAndNavBar];
    [self configAndAddBottomView];
    
    [self addActionToButton];
    [self configButtons];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)hiddenBottomView{
    
    self.bottomView.hidden=YES;
}

-(void)showBottomView{
    
    self.bottomView.hidden=NO;
}

-(void)hiddenPlusBackgroundView{
    
    self.plusBackgroundView.hidden=YES;
}

-(void)showPlusBackgroundView{
    
    self.plusBackgroundView.hidden=NO;
}

#pragma mark - config self.view
-(void)configTabAndNavBar{
    
    self.tabBar.hidden=YES;
    self.navigationController.navigationBar.hidden=YES;
}

-(void)configAndAddBottomView{
    
    [self.view addSubview:self.bottomView];
}

#pragma mark - config bottomView
-(void)configButtons{
    
    self.bottomView.photoExhibitionButton.selected=YES;
    
}

#pragma mark - add action to button
-(void)addActionToButton{
    
    [self.bottomView.photoExhibitionButton addTarget:self action:@selector(pressPhotoExhibitionButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.bottomView.plusButton addTarget:self action:@selector(pressPlusButton:) forControlEvents:UIControlEventTouchUpInside];

    [self.bottomView.meButton addTarget:self action:@selector(pressMeButton:) forControlEvents:UIControlEventTouchUpInside];
    
    //plusBackgroundView button
    [self.plusBackgroundView.joinPhotoMatchButton addTarget:self action:@selector(pressJoinPhotoMatchButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.plusBackgroundView.photographButton addTarget:self action:@selector(pressPhotoGraphUploadButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.plusBackgroundView.albumButton addTarget:self action:@selector(pressAlbumUploadButton:) forControlEvents:UIControlEventTouchUpInside];
    UITapGestureRecognizer* tip = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(plusBackgroundViewTip:)];
    [self.plusBackgroundView addGestureRecognizer:tip];
    
}
- (void)plusBackgroundViewTip:(UITapGestureRecognizer *)tap{
    [self.plusBackgroundView removeFromSuperview];
    self.isShowingplusBackgroundView=NO;
    self.bottomView.plusButton.selected=NO;
    self.bottomView.photoExhibitionButton.hidden=NO;
    self.bottomView.meButton.hidden=NO;
}
#pragma mark - property
-(UIView *)bottomView{
    
    if(_bottomView==nil){
        
        _bottomView=[[[NSBundle mainBundle] loadNibNamed:@"bottomView" owner:nil options:nil] firstObject];
        _bottomView.frame=CGRectMake(0, SCREEN_H-bottomViewH, SCREEN_W, bottomViewH);
    }
    return _bottomView;
}

-(UIView *)plusBackgroundView{
    if(_plusBackgroundView==nil){
        _plusBackgroundView=[[[NSBundle mainBundle] loadNibNamed:@"plusBackgroundView" owner:nil options:nil] firstObject];
        _plusBackgroundView.frame=CGRectMake(0, 0, SCREEN_W, SCREEN_H-bottomViewH);
        _plusBackgroundView.backgroundColor=[UIColor colorWithWhite:0 alpha:0.5];
    }
    return _plusBackgroundView;
}

-(UIButton *)commonButton{
    
    UIButton *commonButton=[[UIButton alloc] init];
    commonButton.contentMode=UIViewContentModeScaleAspectFill;
    
    return commonButton;
}

#pragma mark - pressButton method
-(void)pressPhotoExhibitionButton:(UIButton *)btn{
    self.selectedIndex=0;
    self.bottomView.photoExhibitionButton.selected=YES;
    self.bottomView.plusButton.selected=NO;
    self.bottomView.meButton.selected=NO;
}

-(void)pressPlusButton:(UIButton *)btn{
    //配置弹出view
    if(!self.isShowingplusBackgroundView){
        [self.view addSubview:self.plusBackgroundView];
        self.bottomView.plusButton.selected=YES;
        self.isShowingplusBackgroundView=YES;
        self.bottomView.photoExhibitionButton.hidden=YES;
        self.bottomView.meButton.hidden=YES;
    }else{
        [self.plusBackgroundView removeFromSuperview];
        self.isShowingplusBackgroundView=NO;
        self.bottomView.plusButton.selected=NO;
        self.bottomView.photoExhibitionButton.hidden=NO;
        self.bottomView.meButton.hidden=NO;
    }
}

-(void)pressMeButton:(UIButton *)btn{
    self.selectedIndex=1;
    self.bottomView.meButton.selected=YES;
    self.bottomView.plusButton.selected=NO;
    self.bottomView.photoExhibitionButton.selected=NO;
}

/* 
   使用代理方式，通过影展的VC push 按钮对应的VC，这样可以有一致的视觉体验
*/
//plusDecorationView button
-(void)pressPhotoGraphUploadButton:(UIButton *)btn{
    
    //jump to PhotoGraphUpload VC
    if([self.plusDelegate respondsToSelector:@selector(photoGraphUpload)]){
        [self.plusDelegate photoGraphUpload];
    }
}

-(void)pressAlbumUploadButton:(UIButton *)btn{
    
    //jump to AlbumUpload VC
    if([self.plusDelegate respondsToSelector:@selector(albumUpload)]){
        
        [self.plusDelegate albumUpload];
    }
}

-(void)pressJoinPhotoMatchButton:(UIButton *)btn{
    
    //jump to JoinPhotoMatch VC
    if([self.plusDelegate respondsToSelector:@selector(joinPhotoMatch)]){
        
        [self.plusDelegate joinPhotoMatch];
    }
}

-(void)simulationPressPlusButton{
    
    [self pressPlusButton:nil];
}

-(void)simulationPressMeButton{
    
    [self pressMeButton:nil];
}

-(void)simulationPressPhotoExhibitionButton{
    
   [self pressPhotoExhibitionButton:nil];
}

@end
